//
//  OtherCell.m
//  zhiche--delivery
//
//  Created by LeeBruce on 16/5/27.
//  Copyright © 2016年 LeeBruce. All rights reserved.
//

#import "OtherCell.h"
#import <Masonry.h>

#define buttonheight 30 * kHeight


@implementation OtherCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
//        [self initSubviews];
        self.lastView.backgroundColor = [UIColor clearColor];
    }
    
    return self;
}

-(void)initSubviews
{
    
//    CGRect rightFrame = CGRectMake(screenWidth - 70 * kWidth - 14, 180 * kHeight + 5.5 * kHeight, 70 * kWidth, buttonheight);
//    
//    self.detailButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    self.detailButton.frame = rightFrame;
//    
//    [self.detailButton setTitle:@"确认交车" forState:UIControlStateNormal];
//    [self.detailButton setTitleColor:WhiteColor forState:UIControlStateNormal];
//    self.detailButton.titleLabel.font = Font(14);
//    self.detailButton.backgroundColor = YellowColor;
//    self.detailButton.layer.cornerRadius = 5;
//    
//    [self.contentView addSubview:self.detailButton];
    
    self.detailButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [self.lastView addSubview:self.detailButton];
    [self.detailButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(7 * kWidth);
        make.right.mas_equalTo(-14);
        make.size.mas_equalTo(CGSizeMake(71 * kWidth, buttonheight));
    }];
    
    
    [self.detailButton setTitle:@"确认交车" forState:UIControlStateNormal];
    [self.detailButton setTitleColor:WhiteColor forState:UIControlStateNormal];
    self.detailButton.titleLabel.font = Font(14);
    self.detailButton.backgroundColor = YellowColor;
    self.detailButton.layer.cornerRadius = 5;

    

    
    
}


-(void)setModel:(MineOrderModel *)model
{
    if (_model != model) {
        
        //订单号
        self.orderNumberL.text = [NSString stringWithFormat:@"%@",model.waybillCode];
        //起始地
        if ([model.departProvinceName isEqualToString:model.departCityName]) {
            
            self.startAddress.text = [NSString stringWithFormat:@"%@",model.departProvinceName];
            
        } else {
            self.startAddress.text = [NSString stringWithFormat:@"%@-%@",model.departProvinceName,model.departCityName];
            
        }
        
        //状态
        //个人抢单
        if ([model.bidderType integerValue] == 10) {
            
            self.statusLabel.layer.borderColor = YellowColor.CGColor;
            self.statusLabel.layer.borderWidth = 0.5;
            self.statusLabel.textColor = YellowColor;
            
        } else{
            //公司派单
            self.statusLabel.layer.borderColor = Color_RGB(17, 169, 252, 1).CGColor;
            self.statusLabel.textColor = Color_RGB(17, 169, 252, 1);
            self.statusLabel.layer.borderWidth = 0.5;
            
        }

        self.statusLabel.text = [NSString stringWithFormat:@"%@",model.bidderTypeText];
        self.status.text = [NSString stringWithFormat:@"%@",model.statusText];

        
        
        //起始时间
        
        self.startTimeL.text = [NSString stringWithFormat:@"%@",model.shipmentDate];
        //终止地
        if ([model.receiptProvinceName isEqualToString:model.receiptCityName]) {
            
            self.endAddress.text = [NSString stringWithFormat:@"%@",model.receiptProvinceName];
            
        } else {
            self.endAddress.text = [NSString stringWithFormat:@"%@-%@",model.receiptProvinceName,model.receiptCityName];
            
        }
        
        //终止日期
        self.endTimeL.text = [NSString stringWithFormat:@"%@",model.arriveDate];
        
        //车
        self.carStyleL.text = [NSString stringWithFormat:@"%@",model.detail];
        
//        for (int i = 0; i < model.vehicles.count; i ++) {
//            NSString *string = [NSString stringWithFormat:@"%@-%@-%@辆",model.vehicles[i][@"brandName"],model.vehicles[i][@"vehicleName"],model.vehicles[i][@"amount"]];
//            
//            self.carStyleL.text = [self.carStyleL.text stringByAppendingString:string];
//            self.carStyleL.text = [self.carStyleL.text stringByAppendingString:@"   "];
//            
//        }
//        
//        [self.carStyleL sizeToFit];
//        self.carStyleL.frame = CGRectMake(self.carStyleL.frame.origin.x, self.carStyleL.frame.origin.y, self.carStyleL.frame.size.width, cellHeight);
//        
//        self.scroll.contentSize = CGSizeMake(self.carStyleL.frame.size.width, cellHeight);
        
        
        /*
        //起始地详细地址
        self.startDetailAddress.text = [NSString stringWithFormat:@"%@",model.departUnit];
        //终止地详细地址
        self.endDetailAddress.text = [NSString stringWithFormat:@"%@",model.receiptUnit];
         */
    }
}


-(NSString *)backDateWithString:(NSString *)string
{
    NSDate *nd = [NSDate dateWithTimeIntervalSince1970:[string integerValue]/1000];
    
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"yyyy-MM-dd"];
    NSString *dateString = [dateFormat stringFromDate:nd];
    
    return dateString;
}



@end
